package extraction;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

public class Database {
	
	/**Construit une nouvelle base de donnees
	 * @param dataDepth profondeur des donees a sauvegarder, en minutes
	 * */
	public Database(int dataDepth){
		//Profondeur des donnees sauvegardees, en minutes
		//1 jour = 1440 min, 1 semaine = 10080 min, 31 jours = 44640 min, etc
		this.dataDepth= dataDepth;
	}
	
	/**
	 * @param date
	 * @param obs
	 * */
	public void addObs(Date date, Obs obs){
		dtbDate.add(date);
		dtbObs.add(obs);
	}
	
	/**
	 * @param date
	 * @param obs
	 * */
	public void setObs(Date date, Obs obs){
		dtbObs.set(dtbDate.indexOf(date), obs);
	}
	
	/**
	 * */
	public void resizeDatabase(){
		while(dtbDate.size() > dataDepth){
			dtbDate.remove(1);
			dtbObs.remove(1);
		}
	}
	
	/**
	 * @param date
	 * @return
	 * */
	public boolean dateExists(Date date){
		if(-1 == dtbDate.indexOf(date))
			return false;
		else
			return true;
	}
	
	/**
	 * @param date
	 * @return
	 * */
	public Obs getObs(Date date){
		return dtbObs.get(dtbDate.indexOf(date));
	}
	
	/**
	 * @return
	 * */
	public int getSize(){
		return dtbDate.size();
	}
	
	private ArrayList<Date> dtbDate = new ArrayList<Date>();
	private ArrayList<Obs> dtbObs = new ArrayList<Obs>();
	private int dataDepth;
	SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yy HH:mm");
}
